#include "QNewNotebookDialog.h"
#include <QMessageBox>
#include "MeegoSupport.h"

QNewNotebookDialog::QNewNotebookDialog(MApplicationPage* parent)
{
	ui.setupUi(this);

	QObject::connect(ui.pbOk, SIGNAL(clicked()), this, SLOT(createNewNotebook()));
	QObject::connect(this, SIGNAL(reloadNotebookList()), parent, SLOT(reloadNotebookList()));
}

QNewNotebookDialog::~QNewNotebookDialog()
{

}

void QNewNotebookDialog::createNewNotebook()
{
	if(ui.leNotebookName->text().isEmpty())
	{
		MeegoSupport::MessageBox(trUtf8("Error"), trUtf8("Notebook title is empty"));
	}
	else
	{
		if(QvernoteAPI::Instance()->createNewNotebook(
				ui.leNotebookName->text().toStdString(),
				ui.cbDefault->isChecked(),
				false) == false)
		{
			MeegoSupport::MessageBox(trUtf8("Error"), trUtf8("Unable to create notebook"));
		}
		else
		{
			emit reloadNotebookList();
		}
		this->close();
	}
}

